<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="edu.columbia.ubms.ejb.MainPageSessionBeanRemote" %>
<%@ page import="edu.columbia.ubms.ejb.BlogBoxSessionBeanRemote" %>
<%@ page import="edu.columbia.ubms.ejb.BlogSessionBeanRemote" %>
<%@ page import="edu.columbia.ubms.ejb.Item" %>

<%@ include file="sessionCheck.jsp"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" type="text/css" href="ubms.css" media="screen" />

<script language="javaScript"> 
function openPage(URL) { 
	window.open(URL,'pop','width=300,height=300'); 
} 
</script>
</head>
<body>
<%
//out.println(session.getAttribute("userid"));
int userId = (Integer)session.getAttribute("userid");
//int userId = 1;
%>
<table>
	<tr>
		<td width="100%" aligh="right"><a href="blogBoxSearch.jsp">+</a></td>
	</tr>
</table>
<table width="100%">
	<tr>
<%
try {   
    Context ctx = new InitialContext();		
	MainPageSessionBeanRemote beanRemote = (MainPageSessionBeanRemote)ctx.lookup("MainPageSessionBean/remote");
	Item item[] = beanRemote.userContentsGet(userId, 'R');
	
    for (int i = 0; i < item.length; i++)
    {
		ctx = new InitialContext();		
		BlogBoxSessionBeanRemote beanRemote2 = (BlogBoxSessionBeanRemote)ctx.lookup("BlogBoxSessionBean/remote");
		Item item2 = beanRemote2.blogBoxGet(item[i].getContentId());      	
%>
		<td width="49%" style="vertical-align: top;">
			<table class="tab_mainright"> 
				<tr style="vertical-align: top;">  
					<td width="95%" colspan="3"><%= item2.getBlogboxName() %></td>
					<td width="5%"><a href="mainPageContentDelete.jsp?contenttype=R&contentid=<%=item[i].getContentId()%>&mainpageid=<%=item[i].getMainpageId()%>">X</a></td>
				</tr>
<%
		ctx = new InitialContext();		
		BlogSessionBeanRemote beanRemote3 = (BlogSessionBeanRemote)ctx.lookup("BlogSessionBean/remote");
		Item item3[] = beanRemote3.blogList(item2.getBlogboxId());  
		 
	    for (int j = 0; j < item3.length; j++)
	    {		
%>
				<tr>
					<td width="5%">&nbsp;</td>
					<td width="95%" colspan="3"><a href="blogPopupView.jsp?blogid=<%= item3[j].getBlogId() %>" onclick="window.open(this.href, 'popupName', 'width=600, height=400'); return false"><%= item3[j].getBlogName() %></a></td>
				</tr>
<%	    	
	    }
%>
			</table>
		</td>
<%	        
	    if (i % 2 == 1) {
%>
	</tr>
	<tr>
<%	    	
	    }
    }	
} catch(Exception e) {
    out.println("Error:" + e.getMessage());
}	
	
%>
	</tr>
</table>
</body>
</html>